home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Utils / GParted Live CD / Bin / gparted-livecd-0.2.2.iso / usr_sqfs / bin / cryptdir < prev    next >
Encoding:
Text File  |  2005-07-18  |  1.2 KB  |  64 lines

  1. #!/bin/sh
  2. # \
  3. exec expect -- "$0" ${1+"$@"}
  4. # Name: cryptdir
  5. # Author: Don Libes, NIST
  6. #
  7. # Synopsis:
  8. #      cryptdir [dir]
  9. #    decryptdir [dir]
  10. #
  11. # Encrypt or decrypts the current directory or named directory if given.
  12.  
  13. if {[llength $argv] > 0} {
  14.     cd $argv
  15. }
  16.  
  17. # encrypt or decrypt?
  18. set decrypt [regexp "decrypt" $argv0]
  19.  
  20. set timeout -1
  21. stty -echo
  22. send "Password:"
  23. expect -re "(.*)\n"
  24. send "\n"
  25. set passwd $expect_out(1,string)
  26.  
  27. # Wouldn't want to encrypt/decrypt files with mistyped password!
  28. send "Again:"
  29. expect -re "(.*)\n"
  30. send "\n"
  31. if {![string match $passwd $expect_out(1,string)]} {
  32.     send_user "mistyped password?\n"
  33.     stty echo
  34.     exit
  35. }
  36. stty echo
  37.  
  38. log_user 0
  39. foreach f [glob *] {
  40.     # strip shell metachars from filename to avoid problems
  41.     if {[regsub -all {[]['`~<>:-]} $f "" newf]} {
  42.     exec mv $f $newf
  43.     set f $newf
  44.     }
  45.  
  46.     set strcmp [string compare .crypt [file extension $f]]
  47.     if {$decrypt} {
  48.     # skip files that don't end with ".crypt"
  49.     if {0!=$strcmp} continue
  50.     spawn sh -c "exec crypt < $f > [file root $f]"
  51.     } else {
  52.     # skip files that already end with ".crypt"
  53.     if {0==$strcmp} continue
  54.     spawn sh -c "exec crypt < $f > $f.crypt"
  55.     }
  56.     expect "key:"
  57.     send "$passwd\r"
  58.     expect
  59.     wait
  60.     exec rm -f $f
  61.     send_tty "."
  62. }
  63. send_tty "\n"
  64.